package com.amit;

import java.io.IOException;


import javax.servlet.RequestDispatcher;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SessionDemoServlet extends HttpServlet{
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
		//1.collect the request parameters
		String nm=request.getParameter("name");
		String em=request.getParameter("email");
		
		HttpSession session=request.getSession();
		System.out.println(session.isNew());
		System.out.println(session.getId());
		System.out.println(session.getCreationTime());
		System.out.println(session.getLastAccessedTime());
		
		
		ServletConfig sconfig=getServletConfig();
		ServletContext scontext=sconfig.getServletContext();
		
		request.setAttribute("EM", em);
		session.setAttribute("EM", em);
		scontext.setAttribute("EM", em);
		
		
		RequestDispatcher rd=request.getRequestDispatcher("show.jsp");
		rd.forward(request, response);
		
		
		
	}

}
